<template>
  <auth-button class="delete-css iconCircle" :size="btnSize" :icon="'iconfont iconlajitongshanchudiudiaomianxing'" :title="'删除'" :menuCode="menuCode" :perms="perms" v-if="btnDisplay" @click="delData"></auth-button>
</template>

<script>
  import AuthButton from '@/components/auth/authButton'
  export default {
    components: {AuthButton},
    props: {
      // 所属菜单Code-->全局唯一
      menuCode: {
        type: String,
        default: null
      },
      // 按钮权限标识，外部使用者传入
      perms: {
        type: String,
        default: null
      },
      // 按钮类型
      btnType: {
        type: String,
        default: function () {
          return 'danger'
        }
      },
      // 按钮大小
      btnSize: {
        type: String,
        default: function () {
          return 'small'
        }
      },
      // 是否显示
      btnDisplay: {
        type: Boolean,
        default: function () {
          return true
        }
      },
      // 行数据
      rowData: {
        type: Object,
        default: function () {
          return null
        }
      },
      // 行号
      rowIndex: {
        type: Number,
        default: function () {
          return null
        }
      },
      // 删除文件API
      deleteApi: {
        type: Object,
        default: function () {
          return null
        }
      },
      // 删除窗口的提示信息
      delAlertMsg: {
        type: String,
        default: function () {
          return '此操作会删除该条数据，是否继续？'
        }
      },
      autoDel: {
        type: Boolean,
        default () {
          return true
        }
      }
    },
    computed: {
    },
    methods: {
      delData () {
        let $this = this
        this.$confirm($this.delAlertMsg, '提示', {
          type: 'warning'
        }).then(() => {
          let returnData = {}
          returnData.clickType = 'D'
          returnData.rowData = $this.rowData
          returnData.rowIndex = $this.rowIndex
          if (this.autoDel) {
            $this.deleteApi.del($this.rowData).then(res => {
              if (res.code === 0) {
                $this.success('删除成功')
                this.$emit('operateBtnClick', returnData)
              } else {
                if (res.msg) {
                  $this.error(res.msg)
                } else {
                  $this.error('删除失败')
                }
              }
            })
          } else {
            $this.$emit('operateBtnClick', returnData)
          }
        })
      }
    }
  }
</script>

<style scoped>
  .delete-css {
    display:inline-block;
    margin-left: 10px;
  }
</style>
